package com.dms.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.dms.dao.StudentDao;
import com.dms.model.*;

@Repository
public class StudentDaoImpl extends BaseDaoImpl implements StudentDao {

	@Override
	public Student getStudent(String hql) {	
		return (Student) getSession().createQuery(hql).uniqueResult();
	}

	@Override
	public void updateStudent(Student student) {
		Session session=this.getSession();
		session.merge(student);
		session.flush();
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Student> getStudents(String hql) {
		return getSession().createQuery(hql).list();
	}

	@Override
	public void save(Student student) {
		getSession().save(student);
	}

	@Override
	public void delete(int id) {
		Session session=this.getSession();
		session.delete(session.get(Student.class, id));
		session.flush();
	}
}
